 % Load in the gridmap of each country - from make_country_graphs.m
 % extract the coordinates of each centroid and the list of its neighbors
 % Prepare a shapefile with the list of centroids and destinations through
 % which to compute travel speed
 
country_list_short;
for country_n = 1:Ncountries

    country_icc = char( countries(country_n) );  % country ICC code
    country = icc2name( country_icc );
    
    x_ver_hor = get_threshold(country);
    x_diag = x_ver_hor;
    x_thresh =  x_ver_hor;
    default_cellsize = 0.5;
    largest_connected = 1;
    WP=0;
    osm=0;
    
    %% load grid 
     load( [ path_save_grids,country,'_grid_',...
            num2str( x_diag ),'_',...
            num2str( x_ver_hor ), '_',...
            num2str( default_cellsize ),'_connected', ...
            num2str( largest_connected ), ...
            '_WP', num2str(WP), '_osm', num2str(osm),'.mat' ]);   
   
    places2=country_graph.places2;
    unique_edges=country_graph.unique_edges;    
    discretized_roads=country_graph.discretized_roads;  
    
    % create empty coordinate matrix     
 % load coordinates    
    Xtemp = cell2mat( {places2.X} )';
    Ytemp = cell2mat( {places2.Y} )';

    coordinates = zeros( length(unique_edges),5 );  % [ X1 Y1 X2 Y2 ]
    for j=1:length( unique_edges )

        % coordinates of each link
        coordinates( j, 1:4 ) = [  Xtemp( unique_edges(j,1) )  Ytemp( unique_edges(j,1) ) ...
                                Xtemp( unique_edges(j,2) )  Ytemp( unique_edges(j,2) ) ];
        
        coordinates( j, 5 ) =  discretized_roads(j).avI  ;             
    end

    % write coordinates to spreadsheet (one per country)
    writetable(array2table(coordinates), [path_raw_mapdata, '/OSMR/', country_icc, 'coordinates.csv']);
       
end




            
    